package com.xuanwei.admin.controller;


import com.xuanwei.core.response.ResultVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;

@Controller
@Slf4j
public class PageErrorController implements ErrorController {

    @GetMapping("error")
    @ResponseBody
    public ResultVO errorHandle(HttpServletResponse response){
        int status = response.getStatus();
        if(status ==404){
            log.error("404 page");
            return ResultVO.failResult("请求资源不存在");
        }
        if(status ==500){
            log.error("500 page");
            return ResultVO.failResult("系统异常");
        }

        return ResultVO.failResult("未知错误");

    }
    @Override
    public String getErrorPath() {
        return "error";
    }

}
